File tdir=new File("c:/temp/test"); tdir.mkdir();
File fa=new File("c:/temp/demo.jpg"); long n=fa.length();
File fdir=new File("c:/temp"); String arr[]=fdir.list(); for(String nm:arr) System.out.println(nm);
File fa=new File("c:/temp/demo.sql"); File fb=new File("c:/temp/backup.sql"); fa.renameTo(fb);
File fa=new File("c:/temp/project"); boolean res=fa.isDirectory();
File fa=new File("c:/temp/project"); boolean res=fa.isFile();
File fa=new File("c:/temp/project"); boolean res=fa.exists();
File fa=new File("c:/temp/project"); boolean res=fa.delete();
File fa=new File("c:/temp/demo.sql"); String fname=fa.getName();
File fa=new File("c:/temp/demo.sql"); String fname=fa.getPath();
File fa=new File("c:/temp/demo.sql"); boolean res=fa.canRead();
File fa=new File("c:/temp/demo.sql"); boolean res=fa.canWrite();
import java.util.*; import java.io.*; class demo { public static void main(String args[]) { Scanner stdin=new Scanner(System.in); System.out.print("Enter path "); String path=stdin.next(); File fx=new File(path); if(fx.exists()) { if(fx.isFile()) { if(fx.delete()) System.out.println("File deleted..."); else System.out.println("Cannot delete the file..."); } else System.out.println("Not a File"); } else System.out.println("Path Not Found"); } }
Enter path c:\temp\a2.txt
File deleted...